package com.ruoyi.system.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.MiniStock;
import com.ruoyi.system.service.IMiniStockService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 股票Controller
 * 
 * @author ruoyi
 * @date 2023-11-07
 */
@RestController
@RequestMapping("/system/stock")
public class MiniStockController extends BaseController
{
    @Autowired
    private IMiniStockService miniStockService;

    /**
     * 查询股票列表
     */
    @PreAuthorize("@ss.hasPermi('system:stock:list')")
    @GetMapping("/list")
    public TableDataInfo list(MiniStock miniStock)
    {
        // startPage();
        List<MiniStock> list = miniStockService.selectMiniStockList(miniStock);
        return getDataTable(list);
    }

    /**
     * 导出股票列表
     */
    @PreAuthorize("@ss.hasPermi('system:stock:export')")
    @Log(title = "股票", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, MiniStock miniStock)
    {
        List<MiniStock> list = miniStockService.selectMiniStockList(miniStock);
        ExcelUtil<MiniStock> util = new ExcelUtil<MiniStock>(MiniStock.class);
        util.exportExcel(response, list, "股票数据");
    }

    /**
     * 获取股票详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:stock:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(miniStockService.selectMiniStockById(id));
    }

    /**
     * 新增股票
     */
    @PreAuthorize("@ss.hasPermi('system:stock:add')")
    @Log(title = "股票", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody MiniStock miniStock)
    {
        return miniStockService.insertMiniStock(miniStock);
    }

    /**
     * 查题材已选股票以及可选的股票
     */
    @PreAuthorize("@ss.hasPermi('system:stock:add')")
    @GetMapping("selectableStock")
    public AjaxResult selectableStock(Long subjectId)
    {
        return success(miniStockService.selectableStock(subjectId));
    }
    /**
     * 修改股票
     */
    @PreAuthorize("@ss.hasPermi('system:stock:edit')")
    @Log(title = "股票", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody MiniStock miniStock)
    {
        return toAjax(miniStockService.updateMiniStock(miniStock));
    }

    /**
     * 删除股票
     */
    @PreAuthorize("@ss.hasPermi('system:stock:remove')")
    @Log(title = "股票", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(miniStockService.deleteMiniStockByIds(ids));
    }
}
